package com.kk.permission.huawei;

import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;

import com.kk.permission.GuideConst;
import com.kk.permission.handler.ConfigHandler;
import com.kk.permission.utils.OSUtil;
import com.kk.permission.utils.Permission;
import com.kk.permission.utils.callershow.CallerShowUtils;

import java.util.ArrayList;

public class HuaweiPermissionGuideStrategy extends HuaweiPermissionStrategyBase {
    private static final String TAG = "HuaweiPermissionGuide";

    public HuaweiPermissionGuideStrategy(Context context) {
        super(context);
    }

    protected void actionReadCalllog() {
        super.actionReadCalllog();
        actionTrustApplicationPermission(true);
    }

    protected void actionReadContact() {
        super.actionReadContact();
        actionTrustApplicationPermission(true);
    }

    protected void actionTrustApplicationPermission(boolean z) {
        super.actionTrustApplicationPermission(z);
        try {
            Intent intent = new Intent();
            if (this.mVersion == 2 || this.mVersion == 3 || this.mVersion == 4) {
                intent.setClassName("com.huawei.systemmanager", GuideConst.HUAWEI_APP_PERMISSION_ACTIVITY_NAME);
                startIntentActivities(intent, GuideConst.TRUST_APPLICATION_PERMISSION, this.mAutoGuide);
            } else if (this.mVersion == 1) {
                intent.setClassName("com.huawei.systemmanager", GuideConst.HUAWEI_APP_PERMISSION_ACTIVITY_NAME);
                startIntentActivities(intent, GuideConst.TRUST_APPLICATION_PERMISSION, this.mAutoGuide);
            } else if (this.mVersion == 5) {
                intent.setClassName("com.huawei.systemmanager", GuideConst.HUAWEI_APP_PERMISSION_ACTIVITY_NAME);
                startIntentActivities(intent, GuideConst.TRUST_APPLICATION_PERMISSION, this.mAutoGuide);
            } else if (this.mVersion == 6 || this.mVersion == 9) {
                intent.setClassName("com.huawei.systemmanager", GuideConst.HUAWEI_APP_PERMISSION_ACTIVITY_NAME);
                startIntentActivities(intent, GuideConst.TRUST_APPLICATION_PERMISSION, this.mAutoGuide);
            }
        } catch (Throwable e) {
        }
    }

    @SuppressLint("WrongConstant")
    protected void actionAutoBootPermission()
    {
        super.actionAutoBootPermission();
        try
        {
            Intent localIntent = new Intent();
            if ((this.mVersion != 4) && (this.mVersion != 5) && (!OSUtil.isHuaweiFRD_AL00()))
            {
                if (this.mVersion == 6)
                {
                    localIntent.setClassName("com.huawei.systemmanager", "com.huawei.permissionmanager.ui.MainActivity");
                    startIntentActivities(localIntent, "autoboot_permission", this.mAutoGuide);
                    return;
                }
                if (this.mVersion == 9)
                {
                    localIntent.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.appcontrol.activity.StartupAppControlActivity");
                    startIntentActivities(localIntent, "autoboot_permission", this.mAutoGuide);
                    return;
                }
                localIntent.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.bootstart.BootStartActivity");
                startIntentActivities(localIntent, "autoboot_permission", this.mAutoGuide);
                return;
            }
            localIntent.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.startupmgr.ui.StartupNormalAppListActivity");
            startIntentActivities(localIntent, "autoboot_permission", this.mAutoGuide);
            localIntent.setFlags(268435456);
            return;
        }
        catch (Exception localActivityNotFoundException) {}
    }

    protected void actionToastPermission() {
        super.actionToastPermission();
        Intent intent;
        try {
            int i = this.mVersion;
            if (i == 2 || i == 4 || i == 5 || i == 9 || i == 6) {
                intent = new Intent();
                intent.setClassName("com.huawei.systemmanager", GuideConst.HUAWEI_TOAST_PERMISSION_ACTIVITY_NAME_V2);
                startIntentActivities(intent, GuideConst.TOAST_PERMISSION, this.mAutoGuide);
            } else if (i == 1) {
                intent = new Intent();
                intent.setClassName("com.huawei.systemmanager", GuideConst.HUAWEI_TOAST_PERMISSION_ACTIVITY_NAME_V1);
                startIntentActivities(intent, GuideConst.TOAST_PERMISSION, this.mAutoGuide);
            } else if (i == 3) {
                intent = new Intent();
                intent.setClassName("com.huawei.systemmanager", GuideConst.HUAWEI_TOAST_PERMISSION_ACTIVITY_NAME_V3);
                startIntentActivities(intent, GuideConst.TOAST_PERMISSION, this.mAutoGuide);
            } else if (mVersionNum == 900) {
                intent = new Intent();
                intent.setClassName("com.huawei.systemmanager", GuideConst.HUAWEI_APP_PERMISSION_ACTIVITY_NAME);
                startIntentActivities(intent, GuideConst.TOAST_PERMISSION, this.mAutoGuide);
            }
        } catch (Throwable e) {
            try {
                intent = new Intent();
                intent.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.mainscreen.MainScreenActivity");
                startIntentActivities(intent, GuideConst.TOAST_PERMISSION, this.mAutoGuide);
            } catch (Throwable e2) {
            }
        }
    }

    protected void actionBackgroundPermisssion() {
        super.actionBackgroundPermisssion();
        try {
            Intent intent = new Intent();
            intent.setClassName("com.huawei.systemmanager", GuideConst.HUAWEI_BACKGROUND_PROTECT_PERMISSION_ACTIVITY_NAME);
            startIntentActivities(intent, GuideConst.BACKGROUND_PROTECT_PERMISSION, this.mAutoGuide);
        } catch (Throwable e) {
        }
    }

    protected void actionWhiteListPermisssion() {
        super.actionWhiteListPermisssion();
        try {
            Intent intent = new Intent();
            intent.setClassName("com.huawei.systemmanager", "com.huawei.systemmanager.mainscreen.MainScreenActivity");
            startIntentActivities(intent, "white_list", this.mAutoGuide);
        } catch (Throwable e) {
        }
    }

    protected void actionPermissionDeny(int i) {
        if (3 == i || 1 == i || 2 == i) {
            actionTrustApplicationPermission(true);
            return;
        }
        throw new IllegalArgumentException();
    }

    protected void actionCallogOrContactPermission() {
        super.actionCallogOrContactPermission();
        actionTrustApplicationPermission(true);
    }

    protected void actionDozePermission() {
        super.actionDozePermission();
        try {
            startIntentActivities(new Intent("android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS"), GuideConst.DOZE_PERMISSION, this.mAutoGuide);
        } catch (Throwable e) {
        }
    }

    public ArrayList<String> getPermissionList() {
        ArrayList<String> arrayList = new ArrayList();
        for (Permission permission : ConfigHandler.getInstance().getPermissionList()) {
            switch (permission) {
                case TOAST:
                    arrayList.add(GuideConst.TOAST_PERMISSION);
                    break;
                case CALL_RINGTONE:
//                    if(!PermissionListUtil.isSupportModifyWriteSettingPermission())
                        arrayList.add(GuideConst.CALL_RINGTONE_PERMISSION);
                    break;
                case DIAL_NOTI:
//                    if(!PermissionListUtil.notificationListenerEnable())
                        arrayList.add(GuideConst.DIAL_NOTI_PERMISSION);
                    break;
                case AUTO_BOOT:
                    arrayList.add(GuideConst.AUTOBOOT_PERMISSION);
                    break;
                case SHORTCUT:
                    arrayList.add(GuideConst.INSTALL_SHORT_CUT);
                    break;
                case BACKGROUND_PROTECT:
                    arrayList.add(GuideConst.BACKGROUND_PROTECT_PERMISSION);
                    break;
                default:
                    break;
            }
        }
        return arrayList;
    }

    @SuppressLint("WrongConstant")
    protected void actionDialNotiPermission() {
        super.actionDialNotiPermission();
        try {
            Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
            intent.setFlags(268435456);
            startIntentActivities(intent, GuideConst.DIAL_NOTI_PERMISSION, this.mAutoGuide);
        } catch (ActivityNotFoundException e) {
            String str = TAG;
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append("Failed to start activity:");
            stringBuilder.append(e.toString());
        }
    }

    public HuaweiPermissionAccessbilityHandlerBase getHandlerBase() {
        return new HuaweiPermissionAccessbilityHandler(this.mContext);
    }

    protected void actionCallRingtonePermission() {
        super.actionCallRingtonePermission();
        try {
            CallerShowUtils.jumpToSysMidifySettingActivity(this.mContext);
        } catch (Exception unused) {
        }
    }
}
